import os
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

# 打开谷歌浏览器,访问网址
driver = webdriver.Chrome()
url = 'file:///' + os.path.abspath('html2') + '/注册实例.html'
driver.get(url)
driver.maximize_window()

# 创建select对象
s1 = driver.find_element(By.ID, 'select')
select = Select(s1)

# TODO 选择option,三种方式
time.sleep(3)
select.select_by_index(1)    # 通过索引值选取,从0开始
time.sleep(3)
select.select_by_value('cq')    # 通过value值选取
time.sleep(3)
select.select_by_visible_text('上海')   # 通过文本值选取

# 退出浏览器
time.sleep(3)
driver.quit()